﻿using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Flare
{
    class FunctionalPanelItems
    {
        public object Insert(Type _newpage, int? id = null) { return PreCreateImage("media/IconCreate.png", "Добавить", _newpage, id); }
        public object Edit(Type _newpage, int? id = null) { return PreCreateImage("media/IconEdit.png", "Изменить", _newpage, id); }
        public object Move(Type _newpage, int? id = null) { return PreCreateImage("media/IconMove.png", "Переместить", _newpage, id); }
        public object Delete(Type _newpage, int? id = null) { return PreCreateImage("media/IconDelete.png", "Удалить", _newpage, id); }
        public object PinSet(Type _newpage, int? id = null) { return PreCreateImage("media/IconPin.png", "Закрепить", _newpage, id); }

        private object PreCreateImage(string _source, string _tooltip, Type _page, int? id)
        {
            Grid _top_parent = new Grid();
            _top_parent.Background = Brushes.Transparent;

            Image thisButton = new Image();
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri(_source, UriKind.Relative);
            bi.EndInit();

            thisButton.Width = 48;
            thisButton.Height = 48;
            thisButton.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            thisButton.Source = bi;
            thisButton.ToolTip = _tooltip;

            _top_parent.Children.Add(thisButton);

            _top_parent.PreviewMouseLeftButtonDown += (s, e) =>
                     glob.kernel.ShowPage(_page, id);

            return _top_parent;
        }
    }
}
